package com.iter.devbox.servlet3;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

/**
 * location 竟然要配置真实的文件路径
 * 
 * @author jinxin
 */
@MultipartConfig(fileSizeThreshold=1024, location="d:/", maxFileSize=10240, maxRequestSize=-1)
@WebServlet(urlPatterns={"/myFileUploadServlet"}, asyncSupported=true, name="myFileUploadServlet", loadOnStartup=1, 
initParams={@WebInitParam(name="username", value="hnylj", description="this is initParam")}, description="Servlet3", displayName="The Servlet 3.0")
public class MyFileUploadServlet extends HttpServlet {

	private static final long serialVersionUID = -5437465139169824971L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Part file = request.getPart("file"); 
		file.write(file.getSubmittedFileName());//得到原文件名
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
